﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RegularExpression_demoRegularExpression : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btn_Click(object sender, EventArgs e)
    {
        string ValidationExpression = tb.Text;

        Label ph_lb = new Label();
        ph_lb.ID = "ph_lb";
        ph_lb.Text = "請輸入要驗證的文字";

        TextBox ph_tb = new TextBox();
        ph_tb.ID = "ph_tb";
        ph_tb.Text = string.Empty;

        RegularExpressionValidator regexValidator = new RegularExpressionValidator();
        regexValidator.ID = "regexValidator";
        regexValidator.ControlToValidate = "ph_tb";
        regexValidator.ValidationExpression = ValidationExpression;
        regexValidator.ErrorMessage = string.Format("格式不正確(正確格式為:{0})", ValidationExpression);
        regexValidator.ValidationGroup = "ph";

        Button ph_btn = new Button();
        ph_btn.ID = "ph_btn";
        ph_btn.ValidationGroup = "ph";

        ph.Controls.Clear();
        ph.Controls.Add(ph_lb);
        ph.Controls.Add(ph_tb);
        ph.Controls.Add(regexValidator);
        ph.Controls.Add(ph_btn);
    }

    
}
